package com.sql.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.sql.mapper.MySqlMapper;
import com.sql.pojo.MySql;
import com.sql.pojo.SqlServer;
import com.sql.service.MySqlService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DS("mysql")
public class MySqlServiceImpl implements MySqlService {

    @Resource
    private MySqlMapper mySqlMapper;

    @Autowired
    private SqlServiceImpl sqlService;

    @Override
    public void save(MySql mySql) {
        List<SqlServer> sqlServerList = sqlService.find();
        for (SqlServer sqlServer : sqlServerList) {
            MySql mySql1 = new MySql();
            BeanUtils.copyProperties(sqlServer, mySql1);
            mySqlMapper.insert(mySql1);
        }
    }

    @Override
    public List<MySql> find() {
        return mySqlMapper.selectList(null);
    }
}
